package com.cfx.exercise_42;

public class Sort {

	public static void main(String[] args) {
		int[] arr = new int[]{1,10,5,3,7,9,8};
		//selectSort(arr);
		//bubbleSort(arr);
		reverseArr(arr);
		for (int i : arr) {
			System.out.println(i);
		}
	}
	public static void selectSort(int[] arr){//选择排序
		
		for (int i = 0; i < arr.length-1; i++) {
			for (int j = i+1; j < arr.length; j++) {
				if(arr[i]>arr[j]){
					swap(arr, i, j);
				}
			}
		}
	}
	
	public static void bubbleSort(int[] arr){//冒泡排序
		
		for (int i = 0; i < arr.length-1; i++) {
			
			for (int j = 0; j < arr.length-i-1; j++) {
				
				if(arr[j]>arr[j+1]){
					swap(arr, j, j+1);
				}
			}
		}
	}
	public static void reverseArr(int[] arr){//数组反转
		for (int str = 0, end = arr.length-1;str < end;str++,end--) {
			swap(arr, str, end);
		}
	}
	public static void swap(int[] arr,int i,int j){
		int temp = arr[i];
		arr[i] = arr[j];
		arr[j] = temp;
	}
}
